﻿using UnityEngine;
using Unity.Entities;
using Unity.Collections;
using Unity.Mathematics;

namespace Jinndev.Tile2D {

    public struct SequenceFrame : IComponentData {

        public int2 dimension;          // 序列帧图集维度(行x列)
        
        public int sequenceIndex;       // 当前序列索引
        public int lastSequenceIndex;   // 上一个序列索引

        public float frame;     // 当前帧(浮点型为了方便计算)
        public int lastFrame;   // 上一帧

        public bool dirty;      // 是否需要更新atlasTilingOffset
        public bool play;       // 是否播放(frame随帧率变化)
        public bool reverse;    // 是否倒着播放

        public bool floor;      // 计算frame时的取整方法
        public bool loop;       // 是否循环播放
        public bool resetWhenStop;  // 停止播放时是否重置到第一帧

        public SequenceDefine.Anchor anchor; // 图集排列锚点
        public SequenceDefine.Direction direction; // 帧的排列方向

        public static SequenceFrame Create(RenderConfig renderConfig, int sequenceIndex) {
            return new SequenceFrame {
                dimension = renderConfig.sequenceDefine.dimension,

                sequenceIndex = sequenceIndex,
                lastSequenceIndex = -1,

                frame = 0,
                lastFrame = -1,

                dirty = true,
                play = false,
                reverse = false,

                floor = renderConfig.sequenceDefine.delayStart,
                loop = renderConfig.sequenceDefine.loop,
                resetWhenStop = renderConfig.sequenceDefine.resetWhenStop,
                anchor = renderConfig.sequenceDefine.anchor,
                direction = renderConfig.sequenceDefine.direction
            };
        }

    }

    

}
